package com.weiwen.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionSupport;
import com.weiwen.domain.News;
import com.weiwen.service.NewsService;

public class NewsAction extends ActionSupport{
 
	private static final long serialVersionUID = -1062127339923341737L;
	
	private NewsService newsService;
	private long userId;
	private Map resultMap;
	
	public Map getResultMap() {
		return resultMap;
	}
	public void setResultMap(Map resultMap) {
		this.resultMap = resultMap;
	}
	 
	public long getUserId() {
		return userId;
	}
	public void setUserId(long userId) {
		this.userId = userId;
	}
	public NewsService getNewsService() {
		return newsService;
	}
	public void setNewsService(NewsService newsService) {
		this.newsService = newsService;
	}
	
	/**
	 * 查询最新更新的新闻
	 * @return
	 */
	public String queryNewUpdateNews(){
		System.out.println("queryNewUpdateNews....");
		HashMap map = new HashMap();
		map.put("start", 0);
		map.put("size", 10);
		//1.从数据库中查出的新闻
		System.out.println("queryNewUpdateNews..2..");
		System.out.println("newsService--"+newsService);
		List<News> news = newsService.getNewUpdateNews(map);
		System.out.println("queryNewUpdateNews..3..");
		//2.把新闻转换成json
		for(int i = 0; i < news.size(); i++){
			String title = news.get(i).getTitle();
			System.out.println("新闻标题：" + title);
			System.out.println("录入时间：" + news.get(i).getEntryTime());
		}
		System.out.println("---start json--");
		 
		resultMap = new HashMap();
		resultMap.put("news", news);
		resultMap.put("size", news.size());
		resultMap.put("success", true);
		
		System.out.println("----------------------");
		 
		return SUCCESS;
	}
	
	public String queryNewUpdateNews2(){
		System.out.println("22222222222222222");
		return SUCCESS;
	}
	 
	public static void main(String[] args) {
		new NewsAction().queryNewUpdateNews();
	}
	
}
